package com.zkk.tankgame04;

public class Shot implements Runnable{

    int x;//子弹横坐标
    int y;//子弹纵坐标
    int direct;//子弹方向
    int speed = 3;//子弹速度
    boolean isLive = true;//子弹是否存活

    public Shot(int x, int y, int direct) {
        this.x = x;
        this.y = y;
        this.direct = direct;

    }

    @Override
    public void run() {
        while (true){

          //休眠50ms
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            switch (direct){
                case 0://up
                    y -= speed;
                    break;
                case 1://right
                    x += speed;
                    break;
                case 2://down
                    y += speed;
                    break;
                case 3://left
                    x -= speed;
                    break;
            }
         //   System.out.println("子弹x = " + x + "y =" + y );

            if (!(x > 0 && x < 1000 && y > 0 && y < 750 && isLive)){
                System.out.println("子弹销毁");
                isLive = false;
                break;
            }


        }
           System.out.println("子弹线程结束");
    }


}
